package tokens;

import java.util.ListIterator;
import java.util.Queue;
import java.util.Stack;

import parser.ParserException;

import nodes.AbstractNode;
import nodes.NotNode;
import nodes.binary.AndNode;

/**
 * Creates a NotToken to be used by the Parser
 * 
 * 
 * @author Charlie Hatcher
 */
public class NotToken extends AbstractBinaryToken {
	private static final String NOT_TOKEN = "\\!";

	public NotToken() {
		precedence = 1;
	}

	@Override
	public AbstractNode process() {
		return new NotNode(myModel);
	}

	@Override
	public boolean matchToken(String str, ListIterator<String> it) {
		return str.matches(NOT_TOKEN);
	}

	public String toString() {
		return syntaxBundle.getString("not_label");
	}

	@Override
	public void handleParser(String str, ListIterator<String> it,
			Stack<AbstractBinaryToken> opStack,
			Queue<AbstractNode> outPutQueue, Queue<AbstractNode> queue)
			throws Exception {
		if (!outPutQueue.isEmpty()) {
			AbstractNode temp = outPutQueue.poll();
			outPutQueue.add(new NotToken().process());
			outPutQueue.add(temp);
		} else
			throw ParserException.BAD_SYNTAX;

	}

}
